package com.xinjian.jianba.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xinjian.jianba.dao.dwmid.UserTrackDao;
import com.xinjian.jianba.dto.UserTrackSiteNamesDto;
import com.xinjian.jianba.dto.UserTrackSiteNamesVo;
import com.xinjian.jianba.dto.UserTrackSitePersonsDto;
import com.xinjian.jianba.dto.UserTrackSitePersonsVo;
import com.xinjian.jianba.enity.UserTrackEntity;
import com.xinjian.jianba.service.UserTrackService;
import com.xinjian.jianba.utils.Utils;
@Service
public class UserTrackServiceImpl implements UserTrackService {

	@Autowired
	private UserTrackDao userTrackDao;
	@Override
	public List<UserTrackSiteNamesVo> getSiteNamesByUserId(UserTrackSiteNamesDto userTrackDto) {
		List<UserTrackSiteNamesVo> resultList=new ArrayList<UserTrackSiteNamesVo>();
		List<UserTrackEntity> list=userTrackDao.selectSiteNameByUserId(userTrackDto);
		for(UserTrackEntity userTrackEntity:list){
			UserTrackSiteNamesVo userTrackVo=new UserTrackSiteNamesVo();
			userTrackVo.setAddTime(Utils.convertTimestampToString(userTrackEntity.getAddTime()));
			userTrackVo.setSiteId(userTrackEntity.getSiteId());
			userTrackVo.setSiteName(userTrackEntity.getSiteName());
			userTrackVo.setUserId(userTrackEntity.getUserId());
			userTrackVo.setTimes(userTrackEntity.getTimes());
			//添加地点里的人
			UserTrackSitePersonsDto userTrackSitePersonsDto=new UserTrackSitePersonsDto();
			userTrackSitePersonsDto.setPageNumber(1);
			userTrackSitePersonsDto.setPageSize(6);
			userTrackSitePersonsDto.setSiteId(userTrackEntity.getSiteId());
			userTrackSitePersonsDto.setSiteName(userTrackEntity.getSiteName());
			userTrackSitePersonsDto.setUserId(userTrackEntity.getUserId());
			List<UserTrackSitePersonsVo> relist=selectSitePersonsBySiteId(userTrackSitePersonsDto);
			userTrackVo.setList(relist);
			resultList.add(userTrackVo);
		}
		return resultList;
	}
	@Override
	public List<UserTrackSitePersonsVo> selectSitePersonsBySiteId(UserTrackSitePersonsDto userTrackSitePersonsDto) {
			List<UserTrackSitePersonsVo> reList=new ArrayList<UserTrackSitePersonsVo>();
			List<HashMap<String,Object>> list=userTrackDao.selectSitePersonsBySiteId(userTrackSitePersonsDto);
			for(HashMap<String,Object> map:list){
			UserTrackSitePersonsVo userTrackSitePersonsVo=new UserTrackSitePersonsVo();
			userTrackSitePersonsVo.setHeadAdress(map.get("headAdress")==null?"":(String)map.get("headAdress"));
			userTrackSitePersonsVo.setAddTime(map.get("addTime")==null?"":(String)map.get("addTime"));
			userTrackSitePersonsVo.setNickname(map.get("nickname")==null?"":(String)(map.get("nickname")));
			userTrackSitePersonsVo.setTimes(map.get("times")==null?"":String.valueOf(map.get("times")));
			userTrackSitePersonsVo.setUserId(map.get("userId")==null?"":String.valueOf(map.get("userId")));
			reList.add(userTrackSitePersonsVo);
			}
			return reList;
	}


}
